package com.maxd.modules.selfshop.prize.respository;


import com.maxd.modules.selfshop.prize.entity.SelfPrizeUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SelfPrizeUserJpaRepository extends JpaRepository<SelfPrizeUser, Long> {

    //条件查询带分页
    Page<SelfPrizeUser> findAll(Specification<SelfPrizeUser> specification, Pageable pageable);

    //条件查询
    List<SelfPrizeUser> findAll(Specification<SelfPrizeUser> specification);

    //条件查询
    List<SelfPrizeUser> findAllByUserId(Long userId);

    //今日抽奖次数
    @Query(value = "select count(s.prizeUserId) from SelfPrizeUser s where s.userId=:userId and s.createTime like concat('%',:today,'%') ")
    int findCountByUserId(@Param("userId") Long userId, @Param("today") String today);

}
